package com.smart.mip.system.entity;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.Length;

/**
 * create by scaffold 2017-07-18
 * 
 * @author codefan@sina.com
 * 
 *         系统用户信息null
 */
@Entity
@Table(name = "F_USER_INFO")
public class UserInfo implements java.io.Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * 用户代码 null
	 */
	@Id
	@Column(name = "USER_CODE")
	@GeneratedValue(generator = "assignedGenerator")
	@GenericGenerator(name = "assignedGenerator", strategy = "uuid")
	private String userCode;

	/**
	 * 登录密码 null
	 */
	@Column(name = "USER_PIN")
	@Length(max = 32, message = "字段长度不能大于{max}")
	private String userPin;
	/**
	 * 用户类别 发布任务/接收任务/系统管理
	 */
	@Column(name = "USER_TYPE")
	@Length(max = 1, message = "字段长度不能大于{max}")
	private String userType;
	/**
	 * 状态 T:生效 F:无效
	 */
	@Column(name = "IS_VALID")
	@Length(max = 1, message = "字段长度不能大于{max}")
	private String isValid;
	/**
	 * 登录名 null
	 */
	@Column(name = "LOGIN_NAME")
	@Length(max = 100, message = "字段长度不能大于{max}")
	private String loginName;
	/**
	 * 用户姓名 昵称
	 */
	@Column(name = "USER_NAME")
	@Length(max = 300, message = "字段长度不能大于{max}")
	private String userName;

	@Transient
	private List<UserRole> userRoles;

	// Constructors
	/** default constructor */
	public UserInfo() {
		super();
	}

	/** minimal constructor */
	public UserInfo(String userCode) {

		this.userCode = userCode;

	}

	/** full constructor */
	public UserInfo(String userCode, String userPin, String userType, String isValid, String loginName,
			String userName) {

		this.userCode = userCode;

		this.userPin = userPin;
		this.userType = userType;
		this.isValid = isValid;
		this.loginName = loginName;
		this.userName = userName;
	}

	public List<UserRole> getUserRoles() {
		return userRoles;
	}

	public void setUserRoles(List<UserRole> userRoles) {
		this.userRoles = userRoles;
	}

	public String getUserCode() {
		return this.userCode;
	}

	public void setUserCode(String userCode) {
		this.userCode = userCode;
	}
	// Property accessors

	public String getUserPin() {
		return this.userPin;
	}

	public void setUserPin(String userPin) {
		this.userPin = userPin;
	}

	public String getUserType() {
		return this.userType;
	}

	public void setUserType(String userType) {
		this.userType = userType;
	}

	public String getIsValid() {
		return this.isValid;
	}

	public void setIsValid(String isValid) {
		this.isValid = isValid;
	}

	public String getLoginName() {
		return this.loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getUserName() {
		return this.userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public UserInfo copy(UserInfo other) {

		this.setUserCode(other.getUserCode());

		this.userPin = other.getUserPin();
		this.userType = other.getUserType();
		this.isValid = other.getIsValid();
		this.loginName = other.getLoginName();
		this.userName = other.getUserName();

		return this;
	}

	public UserInfo copyNotNullProperty(UserInfo other) {

		if (other.getUserCode() != null) {
			this.setUserCode(other.getUserCode());
		}

		if (other.getUserPin() != null)
			this.userPin = other.getUserPin();
		if (other.getUserType() != null)
			this.userType = other.getUserType();
		if (other.getIsValid() != null)
			this.isValid = other.getIsValid();
		if (other.getLoginName() != null)
			this.loginName = other.getLoginName();
		if (other.getUserName() != null)
			this.userName = other.getUserName();

		return this;
	}

	public UserInfo clearProperties() {

		this.userPin = null;
		this.userType = null;
		this.isValid = null;
		this.loginName = null;
		this.userName = null;

		return this;
	}
}
